package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Follow;


public class FollowXmlparse {
//	private final static String TAG = "FollowXmlparse";
	private static ArrayList<Follow> follows = null;
	private static Follow followBean = null;
	private static int total;

	public static ArrayList<Follow> getXml(InputStream inSteam) throws Exception {
		XmlPullParser xmpparse = Xml.newPullParser();
		xmpparse.setInput(inSteam, "UTF-8");
		int code = xmpparse.getEventType();
		while (code != XmlPullParser.END_DOCUMENT) {
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				follows = new ArrayList<Follow>();
				break;
			case XmlPullParser.START_TAG:
				if ("total".equals(xmpparse.getName())) {
					String key = xmpparse.nextText();
					total = Integer.parseInt(key);
				}
				if ("user".equals(xmpparse.getName())) {
					followBean = new Follow();
				}
				if (followBean != null) {
					if ("user-id".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						followBean.setUserId(Integer.parseInt(key));
						followBean.setTotal(total);
					}
					if ("user-name".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setUserName(name);
					}
					if ("user-icon".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setUserIcon(name);
					}
					if ("user-location".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setUserLocation(name);
					}
					if ("user-sign".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setUserSign(name);
					}
					if ("is-followed".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setIsFollowed(name);
					}
					if ("total-state".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setTotalState(Integer.parseInt(name));
					}
					if ("following".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setFollowing(Integer.parseInt(name));
					}
					if ("followed".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setFollowed(Integer.parseInt(name));
					}
					if ("credit".equals(xmpparse.getName())) {
						String name = xmpparse.nextText();
						followBean.setCredit(Integer.parseInt(name));
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if ("user".equals(xmpparse.getName())) {
					follows.add(followBean);
					followBean = null;
				}
				break;
			}
			code = xmpparse.next();
		}
		inSteam.close();
		return follows;
	}
}
